//
//  ZHMainController.m
//  ZHS_UCDemo
//
//  Created by Emrys on 2016/11/10.
//  Copyright © 2016年 Emrys. All rights reserved.
//

#import "ZHMainController.h"

#import "ZHRainbowButton.h"

#import "ZHMainDetailController.h"

#import "ZHRequestManager.h"
#import "ZHS_UC_API.h"

#import "ZHMainModel.h"

const NSInteger kZHRedRainbowBtnTag = 101;
const NSInteger kZHYellowRainbowBtnTag = 102;
const NSInteger kZHBlueRainbowBtnTag = 103;

static const NSString *kZHMainCtlTitle = @"首页";

@interface ZHMainController ()

@property (weak, nonatomic) IBOutlet ZHRainbowButton *redRainbowButton;
@property (weak, nonatomic) IBOutlet ZHRainbowButton *yellowRainbowButton;
@property (weak, nonatomic) IBOutlet ZHRainbowButton *blueRainbowButton;

@property(nonatomic, strong) ZHMainModel *mainModel;

@end

@implementation ZHMainController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = (NSString *)kZHMainCtlTitle;
    
    self.redRainbowButton.progress = 0.4;
    self.yellowRainbowButton.progress = 0.7;
    self.blueRainbowButton.progress = 1;
    
    [self loadData];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - loadData
- (void)loadData {
    
    [self refrestWithParameters:nil handle:^(id object, NSError *error) {
        //
        NSLog(@"%@", object);
        if (object) {
            self.mainModel = [ZHMainModel makeModelWithObject:object];
            NSLog(@"%@", self.mainModel);
        } else {
            
        }
    }];
    
}
- (void)refrestWithParameters:(NSDictionary *)parameters handle:(handle)handle {
    
    [[ZHRequestManager sharedManager] request:(NSString *)kZHS_GET_HOME_PAGE_INFO
                                   httpMethod:ZH_POST
                                   parameters:parameters
                                       handle:handle];
}

- (IBAction)didClickRainbow:(ZHButton *)sender {
    
    ZHMainDetailType mainDetailType;
    
    switch (sender.tag) {
        case kZHRedRainbowBtnTag:
            mainDetailType = ZH_ExceedCountType;
            break;
        case kZHYellowRainbowBtnTag:
            mainDetailType = ZH_HasCollectCountType;
            break;
        case kZHBlueRainbowBtnTag:
            mainDetailType = ZH_ContractCountType;
            break;
        default:
            break;
    }
    
    [self toDetailCtlWithType:mainDetailType];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)toDetailCtlWithType:(ZHMainDetailType)mainDetailType {
    
    ZHMainDetailController *mainDetailCtl = [ZHMainDetailController viewController];
    
    mainDetailCtl.mainDetailType = mainDetailType;
    
    [self.navigationController pushViewController:mainDetailCtl animated:YES];
}

@end
